home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / examples / randomblends < prev    next >
Encoding:
Text File  |  2000-05-21  |  2.2 KB  |  64 lines

  1. #!/usr/app/bin/perl
  2.  
  3. eval 'exec /usr/app/bin/perl  -S $0 ${1+"$@"}'
  4.     if 0; # not running under some shell
  5. # <sjburges@gimp.org>
  6. # This is adrian's idea - take random blends and difference them.  You're
  7. # bound to come up w/ something cool eventually.
  8.  
  9. use Gimp qw(:auto __ N_);
  10. use Gimp::Fu;
  11. use Gimp::Util;
  12.  
  13. # Gimp::set_trace(TRACE_ALL);
  14.  
  15. sub randint {
  16.     my ($int) = @_;
  17.     return int(rand()*$int +0.5);
  18.     }    
  19.  
  20. register "random_blends", 
  21.          "Random Blends - take a guess.", 
  22.          "A random approach to art.  Just try it. It might be good.",
  23.          "Seth Burgess", 
  24.          "Seth Burgess <sjburges\@gimp.org>", 
  25.          "1999-03-18",
  26.          N_"<Image>/Filters/Render/Random Blends...", 
  27.          "RGB*, GRAY*", 
  28.          [ 
  29.            [PF_SPINNER, "number", "How many gradients to apply", 7, [1,255,1]], 
  30.             ],
  31.          [],
  32.          ['gimp-1.1'],
  33.          sub {
  34.     my($img,$layer,$numgradients) =@_;
  35.     eval { $img->undo_push_group_start };  # undo is broked for this one.
  36. # add this to the get_state (after its working?)
  37.     $oldgradient = gimp_gradients_get_active();
  38.     ($sel,$x1,$y1,$x2,$y2) = $img->gimp_selection_bounds;
  39.     srand();
  40.  
  41.     @gradientlist = gimp_gradients_get_list();  
  42.     for ($i=0; $i<=$numgradients; $i++) {
  43.         gimp_gradients_set_active(@gradientlist[randint($#gradientlist)]);
  44.         $layer->gimp_blend(CUSTOM,  
  45.                            6,              # DIFFERENCE
  46. # I'd really like to alternate how many arguments in gradient type depending
  47. # on what version of gimp is being run.. Hints anyone? -sjb
  48.                            randint(10),      # gradient type
  49.                            randint(100),     # opacity
  50.                            0,                # offset
  51.                            randint(2),       # repeat
  52.                            0,3,0.2,          # disabled supersampling
  53.                            randint($x2-$x1)+$x1, # x1
  54.                            randint($y2-$y1)+$y1, # y1
  55.                            randint($x2-$x1)+$x1, # x2
  56.                            randint($y2-$y1)+$y1, # y2
  57.                            );
  58.         }
  59.     eval { $img->undo_push_group_end };
  60.     gimp_gradients_set_active($oldgradient);
  61.     return();
  62. };
  63. exit main;
  64.